{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "cea8911b-cf76-4baf-8766-8de4784bfac6",
   "metadata": {},
   "source": [
    "a 在上方创建代码框\n",
    "b 在下方创建代码框\n",
    "dd 删除代码框\n",
    "切换文本框和代码框 y/m 如果现在是代码框按住m文本框(md文件)，如果现在是文本框y变成代码框\n",
    "无论是什么框，在输入完成后 运行：ctrl+enter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7997e407-d2dc-46b7-99fb-102328acb0e8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "==============================\n",
      "    姓名：dongGe\n",
      "    QQ：xxxxxx\n",
      "    手机号：131xxxxx\n",
      "    公司地址：北京市xxxxxx\n",
      "==============================\n"
     ]
    }
   ],
   "source": [
    "print(\"=\"*30)\n",
    "print(\" \"*3,\"姓名：dongGe\")\n",
    "print(\" \"*3,\"QQ：xxxxxx\")\n",
    "print(\" \"*3,\"手机号：131xxxxx\")\n",
    "print(\" \"*3,\"公司地址：北京市xxxxxx\")\n",
    "print(\"=\"*30)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ddbbdbee-c8f5-4a15-bd29-b99c1a189eec",
   "metadata": {},
   "source": [
    "字符串 替换\n",
    "字符串序列.replace(旧子串, 新子串, 替换次数) 返回值：替换后的新的脂字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "94a302de-9062-4556-be89-20db7a2b1a48",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world he it he itstudy he Python\n",
      "hello world he it he itstudy he Python\n",
      "hello world and it and itstudy and Python\n"
     ]
    }
   ],
   "source": [
    "mystr = \"hello world and it and itstudy and Python\"\n",
    "\n",
    "# 结果：hello world he it he itstudy he Python\n",
    "print(mystr.replace('and', 'he'))\n",
    "# 结果：hello world he it he itstudy he Python\n",
    "print(mystr.replace('and', 'he', 10))\n",
    "# 结果：hello world and it and itstudy and Python\n",
    "print(mystr) # 原来的数据"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "132b0a23-d636-4629-a927-95469eeb05ba",
   "metadata": {},
   "source": [
    "字符串 分割\n",
    "字符串序列.split(分割字符, num)，返回值：通过指定的字符分割后的列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5be4b6fe-3a72-4d40-88d2-d80c9e97e6d5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['hello world ', ' it ', ' itstudy ', ' Python']\n",
      "['hello world ', ' it ', ' itstudy and Python']\n",
      "['hello', 'world', 'and', 'it', 'and', 'itstudy', 'and', 'Python']\n",
      "['hello', 'world', 'and it and itstudy and Python']\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'hello world and it and itstudy and Python'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mystr = \"hello world and it and itstudy and Python\"\n",
    "# mystr 按照字符串 'and' 进行分割\n",
    "print(mystr.split('and'))\n",
    "# 结果：['hello world ', ' it ', ' itstudy ', ' Python']\n",
    "# 按照'and'分割成最多两部分\n",
    "print(mystr.split('and', 2))\n",
    "# 结果：['hello world ', ' it ', ' itstudy and Python']\n",
    "\n",
    "# 字符串mystr按空格进行分割，并返回一个包含分割后的子字符串的列表\n",
    "print(mystr.split(' '))\n",
    "# 结果：['hello', 'world', 'and', 'it', 'and', 'itstudy', 'and', 'Python']\n",
    "# 以空格为分隔符最多分割成两部分，并返回分割后的结果\n",
    "print(mystr.split(' ', 2))\n",
    "# 结果：['hello', 'world', 'and it and itstudy and Python']\n",
    "\n",
    "mystr"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "93268948-6dd8-440c-920b-b3278be2cc7e",
   "metadata": {},
   "source": [
    "字符或子串.join(多字符串组成的序列)，返回值：通过指定的字符/字串将数组/元组的元素连接为字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d1e75192-48ca-4011-af21-adaaab6060c5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "chuan_zhi_bo_ke\n",
      "aa...b...cc...ddd\n"
     ]
    }
   ],
   "source": [
    "list1 = ['chuan', 'zhi', 'bo', 'ke']\n",
    "t1 = ('aa', 'b', 'cc', 'ddd')\n",
    "\n",
    "print('_'.join(list1))\n",
    "# 结果：chuan_zhi_bo_ke\n",
    "\n",
    "print('...'.join(t1))\n",
    "# 结果：aa...b...cc...ddd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "3a501dc1-2ff1-4d95-b94a-14dbd90f39d2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   hello world and it and itstuy and Python\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'   hello world and it and itstuy and Python   '"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mystr = \"   hello world and it and itstuy and Python   \"\n",
    "\n",
    "# 结果：HELLO WORLD AND IT AND ITSTUDY AND PYTHON\n",
    "print(mystr.rstrip())\n",
    "\n",
    "mystr"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "997562ce-0be8-434b-99d4-2085e3380846",
   "metadata": {},
   "source": [
    "字符串填充 ljust 从字符串 左侧->右侧 填充到指定长度；默认空格"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6286de00-ebe3-4733-8ae4-1495c457cbfb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello.....\n"
     ]
    }
   ],
   "source": [
    "s = \"hello\"\n",
    "\n",
    "print(s.ljust(10,\".\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2da65f86-6946-4388-90eb-a33e0a98edfa",
   "metadata": {},
   "source": [
    "字符串填充 rjust 从字符串 右侧->左侧 填充到指定长度；默认空格"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "cb9c1992-3b47-43a7-a4d0-ab08f816eb02",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ".....hello\n"
     ]
    }
   ],
   "source": [
    "s = \"hello\"\n",
    "\n",
    "print(s.rjust(10,\".\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ea9d0899-e93e-4975-afdc-31587ad411b7",
   "metadata": {},
   "source": [
    "字符串填充 center 从字符串 两侧 填充到指定长度；默认空格"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "a61a7304-0605-46a5-98c6-6990daa3a4d9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "..hello...\n"
     ]
    }
   ],
   "source": [
    "s = \"hello\"\n",
    "\n",
    "print(s.center(10,\".\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ccbf61c8-66b5-403a-b1b5-8df2184eca62",
   "metadata": {},
   "source": [
    "判断源字符串与指定的字符串开头\n",
    "字符串序列.endswith(子串, 开始位置下标, 结束位置下标) 返回值：Boolean"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a82dabb4-af70-48ee-a1bd-524d7805b782",
   "metadata": {},
   "outputs": [],
   "source": [
    "mystr = \"hello world and it and itstudy and Python\"\n",
    "\n",
    "# 结果：True\n",
    "# 打印以hello开头的字符串\n",
    "print(mystr.startswith('hello'))\n",
    "\n",
    "# 结果False\n",
    "print(mystr.startswith('hello', 5, 20))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "b7990d06-4f00-4a56-8db6-bc11e960cc04",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "mystr = \"hello world and it and itstudy and Python\"\n",
    "\n",
    "print(mystr.endswith('Python'))\n",
    "# 结果：True\n",
    "\n",
    "print(mystr.endswith('python'))\n",
    "# 结果：False\n",
    "\n",
    "# 索引范围从2到19的子字符串是否以'Python'结束\n",
    "print(mystr.endswith('Python', 2, 20))\n",
    "# 结果：False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "428cf974-0cd7-4c3f-9832-78f3dee89abc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Tom', 'Lily', 'Rose', 'xiaoming']\n"
     ]
    }
   ],
   "source": [
    "# 赋值包含三个名字的列表\n",
    "name_list = ['Tom', 'Lily', 'Rose']\n",
    "# 下标为1处插入一个姓名\n",
    "name_list.append('xiaoming')\n",
    "\n",
    "# 结果：['Tom', 'xiaoming', 'Lily', 'Rose']\n",
    "print(name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "90a77b44-a8ca-414e-9bb8-6e4768ca5a30",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Lily\n",
      "['Tom', 'Rose']\n"
     ]
    }
   ],
   "source": [
    "name_list = ['Tom', 'Lily', 'Rose']\n",
    "\n",
    "del_name = name_list.pop(1)\n",
    "\n",
    "# 结果：Lily\n",
    "print(del_name)\n",
    "\n",
    "# 结果：['Tom', 'Rose']\n",
    "print(name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "b6b346e4-35da-4621-bc7e-2eaabe456156",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Lily', 'Rose']\n"
     ]
    }
   ],
   "source": [
    "# 赋值包含三个名字的列表\n",
    "name_list = ['Tom', 'Lily', 'Rose']\n",
    "# 删除下标为0的列表\n",
    "del name_list[0]\n",
    "\n",
    "# 结果：['Lily', 'Rose']\n",
    "print(name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "74405913-d97e-4589-9898-651f27b58964",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Tom', 'Lily']\n"
     ]
    }
   ],
   "source": [
    "name_list = ['Tom', 'Lily', 'Rose']\n",
    "\n",
    "name_list.remove('Rose')\n",
    "\n",
    "# 结果：['Tom', 'Lily']\n",
    "print(name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c1975d5d-eba0-42a0-8bfc-7a41c3d1cb9d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "fb452a5b-2928-4623-aacc-15fcb37cd39b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[]\n"
     ]
    }
   ],
   "source": [
    "name_list = ['Tom', 'Lily', 'Rose']\n",
    "\n",
    "name_list.clear()\n",
    "print(name_list) # 结果： []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "41815b5c-aa12-43c5-a1c6-e632ede7a722",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "ded311d5-a4a9-4a20-a675-22f72ed59a1e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "name_list = ['Tom', 'Lily', 'Rose']\n",
    "# 索引0到2之间进行搜索Lily。\n",
    "print(name_list.index('Lily', 0, 2))  # 1\n",
    "print(name_list.index('Lily'))  # 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "0f78d108-f5e0-47a6-86e9-af03bef53031",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_items([('name', 'Tom'), ('age', 20), ('gender', '男')])\n",
      "('name', 'Tom')\n",
      "('age', 20)\n",
      "('gender', '男')\n"
     ]
    }
   ],
   "source": [
    "dict1 = {'name': 'Tom', 'age': 20, 'gender': '男'}\n",
    "# 循环打印字典键值对 \n",
    "\n",
    "print(dict1.items())  # dict_items([('name', 'Tom'), ('age', 20), ('gender', '男')])\n",
    "# <class 'dict_items'> 是 Python 中字典视图对象 (dict_items) 的类型。字典视图对象表示了字典中的键值对的集合，它们在 Python 3 中被引入用于支持字典操作的一种方式\n",
    "\n",
    "for i in dict1.items():\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "48deefdd-5ec8-4044-9d08-38ecd312dc98",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.15592604967267953\n"
     ]
    }
   ],
   "source": [
    "#import random\n",
    "\n",
    "print(random.random())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "58f996ec-4ca7-4420-87a4-88c9ceff56a1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{100, 10, 20, '111'}\n"
     ]
    }
   ],
   "source": [
    "s1 = {10, 20}\n",
    "s1.add(100)\n",
    "# s1.add([1,2]) # 不能是list类型\n",
    "s1.add('111')\n",
    "s1.add(10)\n",
    "print(s1)  # {100, 10, 20, '111'}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "84a2f934-f2ce-40b9-9d48-2b6efa83e4d3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'cba'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = \"abc\"\n",
    "new_s = \"\"\n",
    "index = len(s)-1\n",
    "while index>=0:\n",
    "    new_s += s[index]\n",
    "    index -= 1\n",
    "new_s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "006c6732-1814-4c71-971c-6d7354084d57",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 "
     ]
    }
   ],
   "source": [
    "for i in range(1,21):\n",
    "    print(i*3,end=\" \")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "6994f951-5b5e-4297-93fd-8be825c6f005",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "234 分数异常×\n",
      "234 分数异常×\n",
      "52134 分数异常×\n",
      "1 分数正常√\n",
      "3 分数正常√\n",
      "43 分数正常√\n",
      "5 分数正常√\n",
      "456 分数异常×\n",
      "234 分数异常×\n",
      "56 分数正常√\n",
      "56 分数正常√\n",
      "67 分数正常√\n",
      "65 分数正常√\n",
      "234 分数异常×\n",
      "2 分数正常√\n",
      "2354 分数异常×\n"
     ]
    }
   ],
   "source": [
    "score = [234,234,52134,1,3,43,5,456,234,56,56,67,65,234,2,2354]\n",
    "for i in score:\n",
    "    if 0<=i<=100:\n",
    "        print(i,\"分数正常√\")\n",
    "    else:\n",
    "        print(i,\"分数异常×\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "03ac5ca4-9c49-47dc-bff1-dda72330db54",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'.;C:\\\\bin'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "os.defpath"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "26ece468-ba66-48d1-9105-eb7a4368e55d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "def return_num():\n",
    "    return 1, 2\n",
    "\n",
    "\n",
    "result = return_num()\n",
    "print(result)  # (1, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "e03f49d7-c5ac-44f9-9064-2542138eed2b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 68, 870, 46, 42, 68]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 列表推导式\n",
    "# 更新\n",
    "arr = [1,34,435,23,21,34]\n",
    "ls = [ i*2 for i in arr ]\n",
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "3fe1faf9-7098-4518-8e53-8195880c2a89",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['A', 'B', 'C', 'B']"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = [\"a\",\"b\",\"c\",\"b\"]\n",
    "[i.upper() for i in arr]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "55e419b3-6ee7-4a58-ab66-44f0cf344b23",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['First', 'Letter', 'To', 'Uppercase']"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 转换\n",
    "arr = [\"first\",\"letter\",\"to\",\"uppercase\"]\n",
    "[i[0].upper()+i[1:] for i in arr]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "7709c829-4a98-4014-8d59-830e527e93f5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[123, 21, 22, 54, 454, 43, 67, 68, 234, 76, 43, 98]"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 更新\n",
    "score = [123,1,2,34,454,23,67,68,234,56,23,98]\n",
    "[ i+20 if i<60 else i for i in score]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "045b92be-7ea3-4544-ace2-9e007113e0f9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 34, 23, 23]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 过滤\n",
    "score = [123,1,2,34,454,23,67,68,234,56,23,98]\n",
    "[i for i in score if i<50]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "d5c648f2-c0d1-4ab8-acf1-16eb747d54ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Letter', 'Uppercase']"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = ['First', 'Letter', 'To', 'Uppercase']\n",
    "[i for i in a if \"e\" in i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "9e99b405-0f03-49ea-9dae-f1a984154455",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 34, 454, 68, 234, 56, 98]"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "score = [123,1,2,34,454,23,67,68,234,56,23,98]\n",
    "[ i for i in score if i%2==0 ]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "07496c6c-5409-4d2d-b09d-a52ffa91a5d1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 生成列表\n",
    "[i for i in range(1,22)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "36e1e35a-259b-4b18-bf05-e6c6f1fbcf94",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'username': '小米', 'age': 20, 'phone': 12278901}\n",
      "小米\n",
      "小米\n",
      "None\n",
      "361@123.com\n"
     ]
    }
   ],
   "source": [
    "# 字典\n",
    "user = {\"username\":\"小米\", \"age\":20, \"phone\":12278901}\n",
    "print(user)\n",
    "print(user[\"username\"])\n",
    "print(user.get(\"username\"))\n",
    "print(user.get(\"email\"))\n",
    "print(user.get(\"email\",\"361@123.com\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "41ec779b-7feb-442f-8144-bd97591e93a0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'username': '小米', 'age': 20, 'phone': 12278901, 'password': '123456'}"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字典\n",
    "user = {\"username\":\"小米\", \"age\":20, \"phone\":12278901}\n",
    "user[\"password\"] = \"123456\"\n",
    "user"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "58608afb-ed31-461e-b507-65e0d42bde46",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'username': '小米', 'age': 20, 'phone': 12278901}"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user = {\"username\":\"小米\", \"age\":20, \"phone\":12278901}\n",
    "user[\"password\"] = \"123456\"\n",
    "user.pop(\"password\")\n",
    "user"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "2d62ceef-19cf-48a7-baef-654d93cecf80",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "title\n",
      "price\n",
      "color\n",
      "手机\n",
      "888\n",
      "['red', 'black']\n",
      "title ['red', 'black']\n",
      "price ['red', 'black']\n",
      "color ['red', 'black']\n"
     ]
    }
   ],
   "source": [
    "goods = {\"title\":\"手机\",\"price\":888,\"color\":[\"red\",\"black\"]}\n",
    "for key in goods.keys():\n",
    "    print(key)\n",
    "for value in goods.values():\n",
    "    print(value)\n",
    "for key,vlaue in goods.items():\n",
    "    print(key,value)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "30532459-bddd-4793-8fda-bc9ac7ab8ac0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[33, 34, 3, 4, 1, 11, 4555, 22]"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 集合 去重\n",
    "a = set([11,22,3,4,34,4555,33,22,1,1,11])\n",
    "a\n",
    "\n",
    "list(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "e3051eca-1968-4c28-910d-c620c650acaa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 2, 3, 4, 99}"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b = set([2,3,4,1])\n",
    "b.add(99)\n",
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "ea2c14db-4152-4379-aef5-be6aa52a0f7b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 2, 3}"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b = set([2,3,4,1])\n",
    "b.remove(4)\n",
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "b68f000e-e836-401c-94a2-3ad7ba669d41",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "source": [
    "# 函数\n",
    "def fn():\n",
    "    print(1)\n",
    "fn()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "4ed08787-71ee-49fc-b909-4d241a205e25",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "def sum(a:int,b:int)->None:\n",
    "    print(a+b)\n",
    "sum(1,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "81987f18-d81a-4123-99c3-d15ed582ed1e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "584"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def sum(arr:list)->int:\n",
    "    total = 0\n",
    "    for i in arr:\n",
    "        total+=i\n",
    "    return total\n",
    "sum([213,345,23,2,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "fc8cb045-df9d-4429-9c2b-ff266510519f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'优'"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def score(val):\n",
    "    if 90<=val<=100:\n",
    "        return \"优\"\n",
    "    elif 80<=val<=90:\n",
    "        return \"良\"\n",
    "    elif 70<=val<=80:\n",
    "        return \"中\"\n",
    "    else:\n",
    "        return \"差\"\n",
    "score(96)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "5bdb83ba-e459-44f2-a30c-1527bbbdc9c8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 2, 3, 4, 5, 6)\n"
     ]
    }
   ],
   "source": [
    "def sum(*arg):\n",
    "    print(arg)\n",
    "sum(1,2,3,4,5,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "d2c20ea0-1ec4-4de1-840d-24b4029308b0",
   "metadata": {},
   "outputs": [],
   "source": [
    "def person(name,age=18):\n",
    "    ...\n",
    "person(\"小米\",20)\n",
    "person(\"小米\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "1a2baa7d-cb88-473d-bf25-44690a7285f6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "100\n",
      "200\n",
      "100\n"
     ]
    }
   ],
   "source": [
    "a = 100\n",
    "def sum():\n",
    "    b = 200\n",
    "    print(a)\n",
    "    print(b)\n",
    "sum()\n",
    "print(a)\n",
    "# print(c) 保错"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "c46d0598-1fde-491e-a516-764e3beee88e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "200\n",
      "100\n"
     ]
    }
   ],
   "source": [
    "a = 100\n",
    "def sum(a):\n",
    "    b = 200\n",
    "    print(a)\n",
    "    print(b)\n",
    "sum(10)\n",
    "print(a)\n",
    "# print(c) 保错"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "c401b037-4b1e-4d37-98a4-fddcda3688af",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99\n",
      "200\n",
      "100\n"
     ]
    }
   ],
   "source": [
    "a = 100\n",
    "def sum(a):\n",
    "    b1 = 200\n",
    "    a = 99\n",
    "    print(a)\n",
    "    print(b1)\n",
    "sum(10)\n",
    "print(a)\n",
    "# print(c) 保错"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "id": "9b90a78f-7cb3-4390-a689-d1cc86cc399c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99\n",
      "200\n",
      "99\n"
     ]
    }
   ],
   "source": [
    "a = 100\n",
    "def sum():\n",
    "    b1 = 200\n",
    "    global a\n",
    "    a = 99\n",
    "    print(a)\n",
    "    print(b1)\n",
    "sum()\n",
    "print(a)\n",
    "# print(c) 保错"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "id": "79fd4224-63e5-42ad-8e99-4e29b2850c1c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'color': '白色', 'proce': 1000, 'brand': '宝马'}\n"
     ]
    }
   ],
   "source": [
    "# 类\n",
    "class Car:\n",
    "    def __init__(self,color,proce,brand):\n",
    "        self.color = color\n",
    "        self.proce = proce\n",
    "        self.brand = brand\n",
    "    def info(self):\n",
    "        return f\"这是一辆{self.brand}的车，价格是{self.price}\"\n",
    "\n",
    "    # def __str__(self):\n",
    "    #     return f\"颜色:{self.color},\"\n",
    "\n",
    "car = Car(\"白色\",1000,\"宝马\")\n",
    "print(car.__dict__)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "id": "7c750cd7-026c-40c2-8a27-1aa458113944",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'hp': 600, 'level': 1, 'attack': 55, 'name': '德玛西亚'}\n",
      "{'hp': 50, 'level': 1, 'attack': 5}\n"
     ]
    }
   ],
   "source": [
    "# 类继承、\n",
    "\n",
    "# 基类\n",
    "class Chart:\n",
    "    def __init__(self,hp,level,attack):\n",
    "        self.hp = hp\n",
    "        self.level = level\n",
    "        self.attack = attack\n",
    "\n",
    "    def is_alive(self):\n",
    "        return self.hp > 0\n",
    "\n",
    "    def chart_info(self):\n",
    "        return f\"目前的血量是：{self.hp}，等级{self.level}，攻击力：{self.attack}\"\n",
    "\n",
    "# 英雄 子类\n",
    "class Hero(Chart):\n",
    "    def __init__(self,hp,level,attack,name):\n",
    "        super().__init__(hp,level,attack)\n",
    "        self.name = name\n",
    "    def getAttack(self,targer):\n",
    "        # 英雄攻击小兵\n",
    "        targer.hp -= 50\n",
    "        \n",
    "gailun = Hero(600,1,55,\"德玛西亚\")\n",
    "print(gailun.__dict__)\n",
    "\n",
    "\n",
    "# 小兵\n",
    "class Minoin(Chart):\n",
    "    def __init__(self,hp,level,attcak):\n",
    "        super().__init__(hp,level,attcak)\n",
    "\n",
    "xiaobing = Minoin(100,1,5)\n",
    "\n",
    "gailun.getAttack(xiaobing)\n",
    "print(xiaobing.__dict__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "id": "554c85a0-a7dd-4e0b-b2b4-8279860a3297",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "小米\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'呵呵呵'"
      ]
     },
     "execution_count": 132,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 类属性和方法\n",
    "class Person:\n",
    "    # 类属性\n",
    "    abc = 99\n",
    "    # 私有类属性\n",
    "    __qq = \"内部的\"\n",
    "    def __init__(self):\n",
    "        self.name = \"小米\" # 实例属性\n",
    "    def info(self): # 实例方法\n",
    "        return \"\"\n",
    "\n",
    "    # 类方法\n",
    "    @classmethod\n",
    "    def other(self):\n",
    "        return self.__qq\n",
    "\n",
    "    # 静态方法 不需要依赖 属性 self cls，实例和类都可以调用\n",
    "    @staticmethod\n",
    "    def abc():\n",
    "        return \"呵呵呵\"\n",
    "p = Person()\n",
    "print(p.name)\n",
    "p.info()\n",
    "Person.abc\n",
    "# p.__qq\n",
    "p.other()\n",
    "p.abc()\n",
    "Person.abc()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f8ddbd44-b041-4f4e-b765-6a736d8f1664",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
